package com.assignwork.vo;

import lombok.Data;
import org.springblade.core.tool.utils.Func;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Data
public class RealLineWorkInfoVO {

    public static final String DAY = "DAY";
    public static final String NIGHT = "NIGHT";

    private String shiftKey;
    private String lineTon;
    private String lineCount;

    private String dayLineTon;
    private String nightLineTon;
    private String dayLineCount;
    private String nightLineCount;
    private String realTon;
    private String realCount;

    public static RealLineWorkInfoVO arr2VO(List<RealLineWorkInfoVO> ls) {
        Map<String, RealLineWorkInfoVO> r = ls.stream().filter(i -> Func.isNoneBlank(i.getShiftKey())).collect(Collectors.toMap(RealLineWorkInfoVO::getShiftKey, a -> a, (k1, k2) -> k1));
        int ton = ls.stream().map(i -> Func.toInt(i.getLineTon())).mapToInt(Integer::valueOf).sum();
        int count = ls.stream().map(i -> Func.toInt(i.getLineCount())).mapToInt(Integer::valueOf).sum();
        RealLineWorkInfoVO vo = new RealLineWorkInfoVO();
        if (r.containsKey(DAY)) {
            vo.setDayLineTon(r.get(DAY).getLineTon());
            vo.setDayLineCount(r.get(DAY).getLineCount());
        }
        if (r.containsKey(NIGHT)) {
            vo.setNightLineTon(r.get(NIGHT).getNightLineTon());
            vo.setNightLineCount(r.get(NIGHT).getNightLineCount());
        }
        vo.setRealTon(ton + "");
        vo.setRealCount(count + "");
        return vo;
    };

}
